function gradient = gauss2DRigidGradient(params, mu1, sigma1, mu2, sigma2)

% compute negative gradient of closed form L2 measure between two Gaussian

dim = length(mu1);
theta = params(3);
trans = params(1:2);
rot = [cos(theta) -sin(theta);
       sin(theta)  cos(theta)];

mu = [rot*mu1']' + trans - mu2;
sigma = rot*sigma1*rot' + sigma2;

mu_grad = gaussMeanGradient(mu, sigma, zeros(size(mu)));
sigma_grad = gaussCovarianceGradient(mu, sigma, zeros(size(mu)));

mu_rot_grad = scaleGradient(rot, mu1);
sigma_rot_grad = quadGradient(rot, sigma1);

rot_theta_grad = [-sin(theta) -cos(theta);
                   cos(theta) -sin(theta)];

rot_grad = zeros(size(rot));
for i = 1:size(rot, 1)
    for j = 1:size(rot, 2)
        m_r_g = mu_rot_grad(:, i, j);
        s_r_g = sigma_rot_grad(:, :, i, j);
        rot_grad(i, j) = sigma_grad(:)'*s_r_g(:) + mu_grad(:)'*m_r_g(:);
    end
end

trans_grad = mu_grad;
theta_grad = rot_grad(:)'*rot_theta_grad(:);

gradient = [trans_grad; theta_grad];
